﻿using SuperSocket.ProtoBase;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace LibMessage.Filters
{
    public class MsgRecvFilter : TerminatorReceiveFilter<StringPackageInfo>
    {
        public MsgRecvFilter() : base(Encoding.UTF8.GetBytes("\r\n"))
        {
        }

        public override StringPackageInfo ResolvePackage(IBufferStream bufferStream)
        {
            string key = "";
            string body = "";
            string allText = bufferStream.ReadString((int)bufferStream.Length, Encoding.UTF8);
            key = Regex.Split(allText, "\u0020")[0];
            body = string.Join("", allText.ToArray().Skip(key.ToArray().Length + 1).ToList());
            return new StringPackageInfo(key, body, null);
        }
    }
}